package com.jlhlyby.tree;


public class SortedArrayToBST {
    public TreeNode sortedArrayToBST(int[] nums) {
        return toBST(nums, 0, nums.length);

    }

    public TreeNode toBST(int[] nums, int left, int right) {
        if (left > right || left < 0 || right > nums.length) {
            return null;
        }
        int index = (left + right) / 2;
        TreeNode node = new TreeNode(nums[index]);
        node.left = toBST(nums, left, index - 1);
        node.right = toBST(nums, index + 1, right);
        return node;
    }
}

